<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>练习3</title>
  <style type="text/css">
    div {
      margin: 100px 0 0 100px;
      background: #999999;
      width: 400px;
      height: 50px;
      align-content: center;
    }
  </style>
  <script src="../js/jquery-3.7.1.min.js"></script>
  <script type="text/javascript">
    $(function () {
      $("input:button").click(function () {
        var $checked = $("input[type=checkbox]:checked");
        var count = $checked.length;
        var str = "";
        $checked.each(function () {
          str += this.value + " ";
        })
        console.log("选中" + count + "个复选框, 分别为:" + str);
      })
    })
  </script>
</head>
<body>
<div>
  <input type="checkbox" name="sport" value="篮球">篮球
  <input type="checkbox" name="sport" value="排球">排球
  <input type="checkbox" name="sport" value="羽毛球">羽毛球
  <input type="checkbox" name="sport" value="乒乓球">乒乓球
  <input type="button" value="选择信息">
</div>
</body>
</html>
